package java8;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.DoubleStream;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class JAVA8 {
    public static void main(String[] args) {
        Function<String, String> upperCase = String::toUpperCase;
        Function<String, String> duplicate = s -> s.concat(s).concat(",");
        System.out.println(upperCase.andThen(duplicate).apply("test"));

        Supplier<Integer> supplier = () -> ThreadLocalRandom.current().nextInt();
        System.out.println(supplier.get());

        //通过stream方法把List或数组转换为流
        Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8).stream().forEach(System.out::println);
        Arrays.stream(new String[]{"sad","dsada","dsada"}).forEach(System.out::println);

        //通过Stream.of方法直接传入多个元素构成一个流
        String[] arr = {"a", "b", "c"};
        Stream.of(arr).forEach(System.out::println);
        Stream.of("a", "b", "c").forEach(System.out::println);
        Stream.of(1,2,"a").map(item -> item.getClass().getName()).forEach(System.out::println);

        Stream.generate(() -> "test").limit(3).forEach(System.out::println);
        Stream.generate(Math::random).limit(10).forEach(System.out::println);

        //演示IntStream和DoubleStream
        IntStream.range(1, 4).forEach(System.out::println);
        IntStream.range(0, 3).mapToObj(i -> "x").forEach(System.out::println);

        IntStream.rangeClosed(1, 3).forEach(System.out::println);
        DoubleStream.of(1.1, 2.2, 3.3).forEach(System.out::println);

        //collect 操作

    }
}

